/*************************************************************************
	> File Name: list_word_count.cc
	> Author: likang
	> Mail:  
	> Created Time: 2014年12月26日 星期五 22时08分30秒
 ************************************************************************/

#include<iostream>
#include<list>
#include<fstream>
#include<algorithm>
#include<cstdlib>

using namespace std;

bool GT4(const string &str) {
	return str.size() >= 4;
}

bool isShorter(const string &s1, const string &s2) {
	return s1.size() < s2.size();
}

int main(int argc, char *argv[]) {

	if (argc == 1) {
		cout << "please input the filename!!" << endl;
		return EXIT_FAILURE;
	}
	ifstream infile(argv[1]);
	if (!infile) {
		cout << "file does not exit!" << endl;
		return EXIT_FAILURE;
	}
	list<string> strlist;
	string str;
	while (infile >> str) {
		strlist.push_back(str);
	}

	//strlist.sort(isShorter);
	cout << endl;
	strlist.sort();
	for (list<string>::iterator it = strlist.begin(); it != strlist.end(); ++it) {
		cout << *it << " ";
	}
	cout << endl;
	strlist.unique();
	for (list<string>::iterator it = strlist.begin(); it != strlist.end(); ++it) {
		cout << *it << " ";
	}
	cout << endl;
	strlist.sort(isShorter);
	list<string>::size_type wc = count_if(strlist.begin(),strlist.end(),GT4);
	for (list<string>::reverse_iterator it = strlist.rbegin(); it != strlist.rend() && wc > 0; ++it,--wc) {
		cout << *it << " ";
	}
	cout << endl;
	return 0;


}
